<template>
  <div class="home">
    <div v-for="item in items" :key="item.id">
      <div
        class="search"
        @click="$router.push('/search')"
        v-if="item.widget_code === 'search'"
      >
        <div class="si">
          <span>{{ item.params.keywords }}</span>
          <img src="https://shqchapp.com/h5/static/image/zoom.png" alt="" />
        </div>
      </div>
      <!-- 轮播图 -->
      <div class="imgSlide" v-if="item.widget_code === 'imgSlide'">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="(img, index) in item.params.list" :key="index">
            <img v-lazy="img.image" alt="" />
          </van-swipe-item>
        </van-swipe>
      </div>
      <!-- nav导航 -->
      <div class="nav" v-if="item.widget_code === 'navBar'">
        <van-grid :border="false" :column-num="5">
          <van-grid-item
            class="nav-item"
            v-for="(img, index) in item.params.list"
            :key="index"
            text="文字"
          >
            <van-image :src="img.image" />
            <div class="nav-cont">{{ img.text }}</div>
          </van-grid-item>
        </van-grid>
      </div>
      <!-- video -->
      <div class="video" v-if="item.widget_code === 'shopvideo'">
        <video
          :src="item.params.list[0].url"
          :poster="item.params.list[0].image"
          :autoplay="false"
          controls
        ></video>
      </div>

      <!-- 秒杀groupPurchase -->
      <div
        class="groupPurchase gods"
        v-if="item.widget_code === 'groupPurchase'"
      >
        <div class="gp-title">{{ item.params.title }}</div>
        <div class="gp-group">
          <div class="gp-item" v-for="gp in item.params.list" :key="gp.id">
            <div class="gp-img"><img :src="gp.image_url" alt="" /></div>
            <div class="des">
              <p class="gp-name">{{ gp.name }}</p>
              <p class="gp-price">￥{{ gp.price }}</p>
              <p class="gp-status">{{ gp.status ? "已结束" : "活动进行中" }}</p>
              <p class="gp-time">
                {{ gp.time }}
                <img
                  class="cart"
                  v-lazy="'https://shqchapp.com/h5/static/image/ic-car.png'"
                />
              </p>
            </div>
          </div>
        </div>
      </div>
      <!-- 商品goods -->
      <div
        class="goods gods"
        v-if="item.widget_code === 'goods'"
        :class="'list' + item.params.column"
      >
        <div class="gp-title">{{ item.params.title }}</div>
        <div class="gp-group">
          <div
            class="gp-item"
            v-for="gp in item.params.list"
            :key="gp.id"
            @click="$router.push('/detail/' + gp.id)"
          >
            <div class="gp-img"><img :src="gp.image_url" alt="" /></div>
            <div class="des">
              <p class="gp-name">{{ gp.name }}</p>
              <p class="gp-price">￥{{ gp.price }}</p>
              <p class="gp-status">
                {{
                  gp.comments_count
                    ? "评论数：" + gp.comments_count + "+"
                    : "暂无评论"
                }}
              </p>
              <p class="gp-time">
                {{ gp.time }}
                <img
                  class="cart"
                  src="https://shqchapp.com/h5/static/image/ic-car.png"
                />
              </p>
            </div>
          </div>
        </div>
      </div>
      <!-- 底部imgSingle -->
      <div class="imgSingle" v-if="item.widget_code === 'imgSingle'">
        <div>
          <img :src="item.params.list[0].image" alt="" style="width: 100%" />
        </div>
      </div>
      <!-- 声明articleClassify -->
      <div
        class="articleClassify"
        v-if="item.widget_code === 'articleClassify'"
      >
        <div class="article">
          <div class="left">
            <p class="title">{{ item.params.list[0].title }}</p>
            <p class="ctime">{{ item.params.list[0].ctime }}</p>
          </div>
          <img :src="item.params.list[0].cover" alt="" />
        </div>
      </div>
    </div>
    <div class="copy">
      <p class="title">&copy;千城汇 版权所有</p>
      <p class="des">备案号：沪ICP备2021013472号</p>
    </div>
  </div>
</template>

<style scoped>
.home {
  overflow: auto;
}
.home .search {
  padding: 0.2rem 0.26rem;
  font-size: 0.25rem;
  color: #888;
}
.home .search img {
  height: 0.5rem;
  width: 0.5rem;
}
.home .search .si {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-indent: 0.15rem;
  background-color: #fff;
  border-radius: 0.5rem;
  background-color: #e9e9e9;
  padding: 0.08rem 0.2rem;
}
.home .imgSlide {
  width: 100%;
  overflow: hidden;
}
.home .imgSlide .my-swipe {
  width: 100%;
  height: 3.3rem;
  overflow: hidden;
}
.home .imgSlide img {
  width: 100%;
}
.nav .nav-item {
  padding: 0 0.1rem;
}
.nav .van-image {
  min-height: 0.64rem;
  min-width: 0.64rem;
}
.nav .nav-cont {
  font-size: 0.2rem;
  color: #666;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}
.video video {
  width: 100%;
}
.gods .gp-title {
  font-size: 0.28rem;
  padding: 0.15rem 0;
  margin-top: 0.1rem;
  text-indent: 0.3rem;
  color: #333;
}
.gods .gp-group {
  width: 100%;
  display: flex;
  overflow: auto;
}
.gods .gp-item {
  display: flex;
  flex: 1;

  min-height: 2.36rem;
  padding: 0.2rem;
  margin-left: 0.26rem;
  margin-bottom: 0.26rem;
  background-color: #f9f9f9;
}
.gods .gp-item .gp-img {
  overflow: hidden;
  width: 1.96rem;
  height: 1.96rem;
  position: relative;
}
.gods .gp-item .gp-img img {
  width: 100%;
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}
.gods .gp-item .des {
  width: 3.4rem;
  min-height: 1.4rem;

  padding: 0.1rem 0 0.1rem 0.2rem;
  position: relative;
}
.gods .des .gp-name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  text-overflow: ellipsis;
  word-wrap: break-word;
  overflow: hidden;
  color: #333;
  width: 100%;

  font-size: 0.28rem;
}
.gods .des .gp-price {
  color: #ff7159 !important;
  font-size: 0.38rem;
}
.gods .des .gp-status {
  font-size: 0.24rem;
}
.gods .des .gp-time {
  color: #ff7159;
  font-size: 0.2rem;
  line-height: 0.2rem;
  margin-top: 0.1rem;
}
.cart {
  width: 0.42rem;
  height: 0.42rem;
  position: absolute;
  bottom: 0.1rem;
  right: 0.1rem;
}

.goods .gp-group {
  display: block;
}
.goods .gp-group .gp-item .gp-img {
  width: 2.5rem;
  height: 2.5rem;
}
.goods .gp-group .gp-item .des {
  flex: 1;
}
.goods .des .gp-price {
  line-height: 1rem;
}
.goods .des .gp-status {
  color: #999;
}
.goods .gp-item {
  margin-bottom: 0;
  margin-left: 0;
}
.list2 .gp-group {
  display: flex;
  flex-wrap: wrap;
}
.list2 .gp-group .gp-item {
  width: 50%;
  display: block;
}
.list2 .gp-group .gp-item .gp-img {
  width: 100%;
  height: 3.36rem;
}
.list2 .des .gp-price {
  line-height: 0.4rem;
  font-size: 0.28rem;
}
.list2 .gp-group .gp-item .des {
  padding: 0 0.2rem;
  font-size: 00.26rem;
  margin-top: 0.1rem;
}
.imgSingle {
  margin-top: 0.2rem;
}
.articleClassify .article {
  display: flex;
  justify-content: space-between;

  padding: 0.2rem 0.26rem;
}
.articleClassify .article .left .title {
  font-size: 0.28rem;
  color: #333;
  min-height: 0.8rem;
  line-height: 0.8rem;
}
.articleClassify .article .left .ctime {
  font-size: 0.24rem;
  color: #999;
}
.articleClassify .article img {
  width: 1.6rem;
  height: 1.6rem;
}
.copy {
  text-align: center;
  font-size: 0.24rem;
  margin: 0.2rem 0;
  color: #999;
  line-height: 0.4rem;
}
</style>

<script>
import { getHome } from "@/api/home.js";
export default {
  name: "HomeView",
  data() {
    return {
      items: [],
    };
  },
  created() {
    getHome({ method: "pages.gethomepageconfig" }).then((res) => {
      if (res.data.status) {
        this.items = res.data.data.items;
        // console.log(this.items);
      }
    });
  },
};
</script>
